package cn.tedu.boot01.controller;


import cn.tedu.boot01.entity.Emp;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
//添加此注解后,就不用在每一个方法上添加@RequestMapping
public class ParamController {
    @RequestMapping("/p1")
    /*@ResponseBody//添加磁珠节后可以通过返回值的方式,给客户端返回数据*/
    public String p1(HttpServletRequest request) {
        String name = request.getParameter("name");
        String age = request.getParameter("age");
        return "测试成功!name=" + name + "age=" + age;
    }

    @RequestMapping("/p2")
    public String p2(String name, int age) {
        return "测试成功!name=" + name + "age=" + age;
    }

    @RequestMapping("/p3")
    public String p3(Emp e) {
        //SpringMVC框架通过反射技术,将接收到的参数直接封装到对象里面
        //soutp
        System.out.println("e = " + e);
        return e.toString();
    }
}
